package com.tbit.main.service.impl;

import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.constant.RedisConstant;
import com.tbit.main.dao.core.AccountConfigDao;
import com.tbit.main.pojo.AccountConfig;
import com.tbit.main.service.AccountConfigService;
import com.tbit.main.service.RedisService;
import com.tbit.main.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 代理商配置
 *
 * @author Leon
 * 2019年11月19日 上午10:49:57
 */
@Service("accountConfigService")
public class AccountConfigServiceImpl implements AccountConfigService {
    @Autowired
    private AccountConfigDao accountConfigDao;
    @Autowired
    private RedisService redisService;

    @Override
    public AccountConfig getByAccountId(Integer accountId) {
        return accountConfigDao.getByAccountId(accountId);
    }

    @Override
    public List<AccountConfig> getAll() {
        return accountConfigDao.getAll();
    }

    @Override
    public void update(AccountConfig accountConfig) {
        accountConfigDao.update(accountConfig);
        redisService.del(RedisConstant.CONFIG_KEY_PREFIX + accountConfig.getAccountId());
    }

    @Override
    public List<AccountConfig> getByListAccountId(List<Integer> accountId) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountIds, StringUtil.getListString(accountId));
        return accountConfigDao.getByListAccountId(map);
    }

}
